package com.xidian.zhiancloud.service.riskcontrol.riskevaluate;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.xidian.zhiancloud.dao.riskcontrol.riskevaluate.TRiskEvaMethSetCriteMapper;
import com.xidian.zhiancloud.model.riskcontrol.TRiskEvaMethSetCriteList;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

/**
 * 风险管控-系统设置-风险评价方法设置-两个字段
 */
@Service
public class TRiskEvaMethSetCriteService extends ServiceImpl<TRiskEvaMethSetCriteMapper, TRiskEvaMethSetCriteList> {

    @Autowired
    TRiskEvaMethSetCriteMapper tRiskEvaMethSetCriteMapper;

    public List<Map<String,String>> getTRiskEvaMethSetCriteList(
            Long companyId,String evaMethodSetId,String criteria){
        return tRiskEvaMethSetCriteMapper.getTRiskEvaMethSetCriteList
                (companyId,evaMethodSetId,criteria);
    }

    public List<Map<String, Object>> getByEvaMethodSetIdOneList
            (Long companyId,String evaMethodSetId){
        return tRiskEvaMethSetCriteMapper.getByEvaMethodSetIdOneList
                (companyId,evaMethodSetId);
    }

    public List<Map<String, Object>> getByEvaMethodSetIdTwoList
            (Long companyId,String evaMethodSetId){
        return tRiskEvaMethSetCriteMapper.getByEvaMethodSetIdTwoList
                (companyId,evaMethodSetId);
    }

    public int addTRiskEvaMethSetCrite(TRiskEvaMethSetCriteList tRiskEvaMethSetCrite){
        return tRiskEvaMethSetCriteMapper.addTRiskEvaMethSetCrite(tRiskEvaMethSetCrite);
    }

    public int updateTRiskEvaMethSetCrite(String id,
             TRiskEvaMethSetCriteList tRiskEvaMethSetCrite){
        return tRiskEvaMethSetCriteMapper.updateTRiskEvaMethSetCrite
                (id,tRiskEvaMethSetCrite);
    }

    public int deleteTRiskEvaMethSetCrite(String id){
        List<String> list = getList(id);
        return tRiskEvaMethSetCriteMapper.deleteTRiskEvaMethSetCrite(list);
    }

    /**
     * id放入list
     * @param id id(多个已逗号分隔)
     * @return List集合
     */
    public List<String> getList(String id) {
        List<String> list = new ArrayList<String>();
        String[] str = id.split(",");
        for (int i = 0; i < str.length; i++) {
            list.add(str[i]);
        }
        return list;
    }


}
